package com.self.structure;

public class NStack {

    private int cap;

    private int[] data;

    private int index = 0;

    private int size = 0;

    public NStack(int cap) {
        this.cap = cap;
        this.data = new int[cap];
    }

    public boolean isEmpty() {
        return this.size <= 0;
    }

    public int size() {
        return this.size;
    }

    public void push(int el) {
        if(this.size == data.length) {
            return;
        }

        this.data[index++] = el;
        this.size++;
    }

    public int pop() {
        if(isEmpty()) {
            throw new RuntimeException("stack is empty");
        }

        int v = data[--index];
        this.size--;
        return v;
    }

    public static void main(String[] args) {
        NStack nStack = new NStack(5);
        for (int i = 0; i< 5;i++) {
            nStack.push(i);
        }

        while (!nStack.isEmpty()) {

            System.out.println(nStack.pop());
        }
    }
}
